-
Notifications
You must be signed in to change notification settings - Fork 12.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Tidy CFTE/MIRI #53609
Tidy CFTE/MIRI #53609
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @eddyb (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
|
Ah crap, I accidentally added those submodule changes. Fixing. |
f1d4b19
to
b114492
Compare
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Leave a newline after the header (here and elsewhere).
ba0695d
to
27b8c92
Compare
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
r? @RalfJung |
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
src/librustc/mir/interpret/error.rs
Outdated
@@ -309,7 +319,8 @@ impl<'tcx, O> EvalErrorKind<'tcx, O> { | |||
ReadForeignStatic => | |||
"tried to read from foreign (extern) static", | |||
InvalidPointerMath => | |||
"attempted to do invalid arithmetic on pointers that would leak base addresses, e.g. comparing pointers into different allocations", | |||
"attempted to do invalid arithmetic on pointers that would leak base addresses, | |||
e.g. comparing pointers into different allocations", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs a backslash to not change the actual string being computed:
"attempted to do invalid arithmetic on pointers that would leak base addresses, \
e.g. comparing pointers into different allocations",
Here and elsewhere.
src/librustc/mir/interpret/error.rs
Outdated
@@ -441,7 +454,8 @@ impl<'tcx, O: fmt::Debug> fmt::Debug for EvalErrorKind<'tcx, O> { | |||
} | |||
NoMirFor(ref func) => write!(f, "no mir for `{}`", func), | |||
FunctionPointerTyMismatch(sig, got) => | |||
write!(f, "tried to call a function with sig {} through a function pointer of type {}", sig, got), | |||
write!(f, "tried to call a function with sig {} through a\ | |||
function pointer of type {}", sig, got), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This removes the space.
"a\
b"
is the string "ab"
. See playground.
You should add a space in front of the backslash.
Please compile-test code locally before pushing it. :)
|
f30d4fa
to
f5ce1d5
Compare
@RalfJung Fixed everything & rebased. |
Oh ffs the submodule changes made it through |
f5ce1d5
to
7d30ba9
Compare
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
☔ The latest upstream changes (presumably #52011) made this pull request unmergeable. Please resolve the merge conflicts. |
Please do not use merging to resolve conflicts; always do a rebase. And sorry that you are experiencing all these conflicts, that is often a problem with PRs touching so many files :/ I will try to get it reviewed ASAP once you fixed them. |
src/librustc/mir/interpret/error.rs
Outdated
@@ -363,11 +374,13 @@ impl<'tcx, O> EvalErrorKind<'tcx, O> { | |||
Layout(_) => | |||
"rustc layout computation failed", | |||
UnterminatedCString(_) => | |||
"attempted to get length of a null terminated string, but no null found before end of allocation", | |||
"attempted to get length of a null terminated string, but no null found before end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing \
src/librustc/mir/interpret/error.rs
Outdated
HeapAllocZeroBytes => | ||
"tried to re-, de- or allocate zero bytes on the heap", | ||
HeapAllocNonPowerOfTwoAlignment(_) => | ||
"tried to re-, de-, or allocate heap memory with alignment that is not a power of two", | ||
"tried to re-, de-, or allocate heap memory with alignment that is not a power of |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing \
src/librustc_mir/interpret/cast.rs
Outdated
fn cast_from_float(&self, bits: u128, fty: FloatTy, dest_ty: Ty<'tcx>) -> EvalResult<'tcx, Scalar> { | ||
|
||
fn cast_from_float(&self, bits: u128, fty: FloatTy, dest_ty: Ty<'tcx>) | ||
-> EvalResult<'tcx, Scalar> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Our usual way of formatting function signatures multi-line is
fn cast_from_float(
&self,
bits: u128,
fty: FloatTy,
dest_ty: Ty<'tcx>
) -> EvalResult<'tcx, Scalar> {
Please follow that.
@@ -378,7 +392,8 @@ impl<'a, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M | |||
Ok(Value::new_slice(Scalar::Ptr(ptr), s.len() as u64, self.tcx.tcx)) | |||
} | |||
|
|||
pub(super) fn resolve(&self, def_id: DefId, substs: &'tcx Substs<'tcx>) -> EvalResult<'tcx, ty::Instance<'tcx>> { | |||
pub(super) fn resolve(&self, def_id: DefId, substs: &'tcx Substs<'tcx>) | |||
-> EvalResult<'tcx, ty::Instance<'tcx>> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same for the multi-line function signature style.
if did.is_local() && self.tcx.has_typeck_tables(did) && self.tcx.typeck_tables_of(did).tainted_by_errors { | ||
if did.is_local() | ||
&& self.tcx.has_typeck_tables(did) | ||
&& self.tcx.typeck_tables_of(did).tainted_by_errors { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After a multi-line conditional, please put the {
on its own line.
@@ -757,7 +776,8 @@ impl<'a, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M | |||
} else { | |||
last_span = Some(span); | |||
} | |||
let location = if self.tcx.def_key(instance.def_id()).disambiguated_data.data == DefPathData::ClosureExpr { | |||
let location = if self.tcx.def_key(instance.def_id()).disambiguated_data.data | |||
== DefPathData::ClosureExpr { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dito for separate line for {
This is the official style for non-inherent impls:
so I'd say having indented where clauses is in the same spirit. Also, CI found two lines that are still too long. |
src/librustc_mir/interpret/cast.rs
Outdated
bits: u128, | ||
fty: FloatTy, | ||
dest_ty: Ty<'tcx> | ||
) -> EvalResult<'tcx, Scalar> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The line with the arrow should not be indented:
fn cast_from_float(
&self,
bits: u128,
fty: FloatTy,
dest_ty: Ty<'tcx>
) -> EvalResult<'tcx, Scalar> {
// code goes here
That nicely groups the arguments.
@RalfJung Fixed :) |
&self, | ||
def_id: DefId, | ||
substs: &'tcx Substs<'tcx> | ||
) -> EvalResult<'tcx, ty::Instance<'tcx>> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you missed one :)
src/librustc_mir/interpret/memory.rs
Outdated
pub fn read_scalar(&self, ptr: Pointer, ptr_align: Align, size: Size) -> EvalResult<'tcx, ScalarMaybeUndef> { | ||
self.check_relocation_edges(ptr, size)?; // Make sure we don't read part of a pointer as a pointer | ||
pub fn read_scalar(&self, ptr: Pointer, ptr_align: Align, size: Size) | ||
-> EvalResult<'tcx, ScalarMaybeUndef> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And another one (oops I think I had missed that before as well)
src/librustc_mir/interpret/place.rs
Outdated
pub fn unpack_unsized_mplace( | ||
&self, | ||
mplace: MPlaceTy<'tcx> | ||
) -> EvalResult<'tcx, MPlaceTy<'tcx>> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here as well
I think those are the last three... sorry I hadn't seen them earlier.^^ |
@RalfJung I think I got them all now 😄 . Thanks! |
:) Let us see if CI is happy. |
@RalfJung SHIP IT |
I will :) @bors r+ |
📌 Commit e07c154 has been approved by |
@RalfJung Cheers! Thanks for walking me through my first PR! |
Thanks for contributing :) |
☀️ Test successful - status-appveyor, status-travis |
Miri engine cleanup * Unify the two maps in memory to store the allocation and its kind together. * Share the handling of statics between CTFE and miri: The miri engine always uses "lazy" `AllocType::Static` when encountering a static. Acessing that static invokes CTFE (no matter the machine). The machine only has any influence when writing to a static, which CTFE outright rejects (but miri makes a copy-on-write). * Add an `AllocId` to by-ref consts so miri can use them as operands without making copies. * Move responsibilities around for the `eval_fn_call` machine hook: The hook just has to find the MIR (or entirely take care of everything); pushing the new stack frame is taken care of by the miri engine. * Expose the intrinsics and lang items implemented by CTFE so miri does not have to reimplement them. * Allow Machine to hook into foreign statics (used by miri to get rid of some other hacks). * Clean up function calling. * Switch const sanity check to work on operands, not mplaces. * Move const_eval out of rustc_mir::interpret, to make sure that it does not access private implementation details. In particular, we can finally make `eval_operand` take `&self`. :-) Should be merged after #53609, across which I will rebase.
Miri engine cleanup * Unify the two maps in memory to store the allocation and its kind together. * Share the handling of statics between CTFE and miri: The miri engine always uses "lazy" `AllocType::Static` when encountering a static. Acessing that static invokes CTFE (no matter the machine). The machine only has any influence when writing to a static, which CTFE outright rejects (but miri makes a copy-on-write). * Add an `AllocId` to by-ref consts so miri can use them as operands without making copies. * Move responsibilities around for the `eval_fn_call` machine hook: The hook just has to find the MIR (or entirely take care of everything); pushing the new stack frame is taken care of by the miri engine. * Expose the intrinsics and lang items implemented by CTFE so miri does not have to reimplement them. * Allow Machine to hook into foreign statics (used by miri to get rid of some other hacks). * Clean up function calling. * Switch const sanity check to work on operands, not mplaces. * Move const_eval out of rustc_mir::interpret, to make sure that it does not access private implementation details. In particular, we can finally make `eval_operand` take `&self`. :-) Should be merged after #53609, across which I will rebase.
Miri engine cleanup * Unify the two maps in memory to store the allocation and its kind together. * Share the handling of statics between CTFE and miri: The miri engine always uses "lazy" `AllocType::Static` when encountering a static. Acessing that static invokes CTFE (no matter the machine). The machine only has any influence when writing to a static, which CTFE outright rejects (but miri makes a copy-on-write). * Add an `AllocId` to by-ref consts so miri can use them as operands without making copies. * Move responsibilities around for the `eval_fn_call` machine hook: The hook just has to find the MIR (or entirely take care of everything); pushing the new stack frame is taken care of by the miri engine. * Expose the intrinsics and lang items implemented by CTFE so miri does not have to reimplement them. * Allow Machine to hook into foreign statics (used by miri to get rid of some other hacks). * Clean up function calling. * Switch const sanity check to work on operands, not mplaces. * Move const_eval out of rustc_mir::interpret, to make sure that it does not access private implementation details. In particular, we can finally make `eval_operand` take `&self`. :-) Should be merged after #53609, across which I will rebase.
Fixes #53596